package com.jielihaofeng.springboot.wcx.controller;


import com.jielihaofeng.springboot.wcx.common.Result;
import com.jielihaofeng.springboot.wcx.entity.WorkCalendar;
import com.jielihaofeng.springboot.wcx.service.WorkCalendarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Johnnie Wind
 * @since 2021-09-23
 */
@RestController
@RequestMapping("/workCalendar")
public class WorkCalendarController {

    @Autowired
    WorkCalendarService workCalendarService;

    @GetMapping
    public Result get(){
        List<WorkCalendar> list = workCalendarService.list();
        return new Result<List<WorkCalendar>>().message("获取工作日历成功！").data(list);
    }

    @PostMapping
    public Result add(@RequestBody WorkCalendar workCalendar){
        boolean save = workCalendarService.save(workCalendar);
        if (save){
            return new Result<List<WorkCalendar>>().message("保存工作日历成功！");
        }
        return new Result<List<WorkCalendar>>().fail("保存工作日历失败！");
    }

    @PutMapping
    public Result modify(@RequestBody WorkCalendar workCalendar){
        boolean update = workCalendarService.updateById(workCalendar);
        if (update){
            return new Result<List<WorkCalendar>>().message("修改工作日历成功！");
        }
        return new Result<List<WorkCalendar>>().fail("修改工作日历失败！");
    }

    @DeleteMapping("/{id}")
    public Result delete( @PathVariable("id") String id){
        boolean delete = workCalendarService.removeById(id);
        if (delete){
            return new Result<List<WorkCalendar>>().message("删除工作日历成功！");
        }
        return new Result<List<WorkCalendar>>().fail("删除工作日历失败！");
    }

}

